package eu.webhib.test.base;

import eu.webhib.frmwrk.utils.ApplProperties;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;

//
public class ApplResource {

   private static final Logger log = Logger.getLogger(ApplResource.class);
   private static Properties prop = new Properties();

   public static void setPropertiesFile(String fileName) {
      /** try to load from deployed war archive */
      try {
         InputStream stream = ApplProperties.class.getClassLoader().getResourceAsStream(fileName);
         if (stream == null) {
            log.warn("Properties file '" + fileName + "' not found in war archive");
         } else {
            prop.load(stream);
            log.warn("Properties file '" + fileName + "' loaded from war archive");
            stream.close();
         }
      } catch (Exception ex) {
         log.fatal("Error reading properties file '" + fileName + "' from war archive", ex);
      }
   }

   public static String get(String key) {
      return prop.getProperty(key);
   }

   public static int getInt(String key) {
      return Integer.parseInt(prop.getProperty(key));
   }

   public static double getDouble(String key) {
      return Double.parseDouble(prop.getProperty(key));
   }
}
